package com.yzf.web;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.yzf.entity.Employee;
import com.yzf.entity.Project;
import com.yzf.service.ProjectService;
import com.yzf.service.SignService;
import com.yzf.util.web.ServletUtil;

public class main extends HttpServlet {

	
	private static final long serialVersionUID = 1L;

	
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		String name = request.getParameter("name");
		String pwd = request.getParameter("pwd");
		Employee em = new SignService().findByNameAndPwd(name,pwd);
		if(em!=null){
			ServletUtil.getSession(request).setAttribute("employee", em);
			
			List<Project> list = new ProjectService().findByEid(em.getId());
			ServletUtil.setRequestAttribute("list", list, request);
			ServletUtil.forword(request, response, "main");
		}else{
			ServletUtil.setRequestAttribute("state", "1001", request);
			ServletUtil.forword(request, response, "login");
		}
	}
	@Override
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		Employee em = (Employee) ServletUtil.getSession(request).getAttribute("employee");
		List<Project> list = new ProjectService().findByEid(em.getId());
		ServletUtil.setRequestAttribute("list", list, request);
		ServletUtil.forword(request, response, "main");
	}
}
